<template>
  <div>
    <el-button type="primary" @click="handleUpload">上传</el-button>
    <input style="display: none" ref="file" type="file" />
    <div>{{ fileName.name }}</div>
  </div>
</template>
<script setup>
import axios from 'axios';
const baseURL = import.meta.env.VITE_APP_BASE_API;
const url = '/admin/file/upload/element';
const fileName = ref({});
const file = ref();

onMounted(() => {
  addEventListenerFile(file.value);
});

// 监听文件上传
const addEventListenerFile = (file) => {
  file.addEventListener("change", (e) => {
      let { files } = e.target;
      console.log(files);
      fileName.value = files[0];
  });
};

// 选择上传文件
const handleUpload = () => {
  file.value.click();
};
</script>
